import { ElMessage, ElMessageBox } from 'element-plus';
import 'element-plus/theme-chalk/el-message.css';

// 定义一个唯一标识
const instance = Symbol('instance');

class MessageService {
  success(text: string, duration?: number): void {
    this[instance]('success', text, duration ?? 3000);
  }
  error(text: string, duration?: number): void {
    this[instance]('error', text, duration ?? 3000);
  }
  warning(text: string, duration?: number): void {
    this[instance]('warning', text, duration ?? 3000);
  }
  info(text: string, duration?: number): void {
    this[instance]('info', text, duration ?? 3000);
  }
  [instance](type: 'success' | 'error' | 'warning' | 'info', text: string, duration: number) {
    ElMessage[type]({
      message: text,
      duration
    });
  }
}

export const message = new MessageService();

export const messageBox = ElMessageBox;
